class Solution(object):
    def sumSubseqWidths(self, nums):
        nums.sort()
        ans = 0
        t_sum = 0
        t_count = 0
        now_count = 1
        base = 10 ** 9 + 7
        for num in nums:
            ans = (ans + num * t_count - t_sum) % base
            t_sum = (t_sum * 2 + num) % base
            t_count = (t_count + now_count) % base
            now_count = 2 * now_count % base
        return ans



data = Solution()
nums = [1, 1, 2, 3]
print(data.sumSubseqWidths(nums))
